
package graph.tests;

import junit.framework.*;
import java.util.*;

import graph.*;

public class PathFinderTest extends TestCase {

    private PathFinder finder;

    private AdjacencyMatrixGraph graph;
    private final static String A = "A";
    private final static String B = "B";
    private final static String C = "C";
    private final static String D = "D";
    private final static String E = "E";
    private final static String F = "F";
    private final static String G = "G";
    private final static String H = "H";

    protected final static int VERTICES_NUMBER = 5;

    public PathFinderTest(String s) {
        super(s);
    }

    protected void setUp() {
        graph = new AdjacencyMatrixGraph(VERTICES_NUMBER);
        graph.addVertex(A);
        graph.addVertex(B);
        graph.addVertex(C);
        graph.addVertex(D);
        graph.addVertex(E);
        graph.addEdge(A, B, 5);
        graph.addEdge(B, C, 4);
        graph.addEdge(C, D, 8);
        graph.addEdge(D, C, 8);
        graph.addEdge(D, E, 6);
        graph.addEdge(A, D, 5);
        graph.addEdge(C, E, 2);
        graph.addEdge(E, B, 3);
        graph.addEdge(A, E, 7);
        finder = new PathFinder(graph);
    }

    protected void tearDown() {
    }

    public void testFindPathsWithExactLength() {
        ArrayList solutions = (ArrayList) finder.findPathsWithExactLength(A, C, 4);
        Iterator iter = solutions.iterator();
        System.out.println("Solutions for A, C with exact length = 4");
        while (iter.hasNext()) {
            String sol = iter.next().toString();
            assertTrue(sol.equals("A-B-C-D-C") || sol.equals("A-D-C-D-C") || sol.equals("A-D-E-B-C"));
            System.out.println(sol);
        }
    }

    public void testFindPathsWithMaximumLength() {
        ArrayList solutions = (ArrayList) finder.findPathsWithMaximumLength(C, C, 3);
        Iterator iter = solutions.iterator();
        System.out.println("Solutions for C, C with maximum length = 3");
        while (iter.hasNext()) {
            String sol = iter.next().toString();
            assertTrue(sol.equals("C-D-C") || sol.equals("C-E-B-C"));
            System.out.println(sol);
        }
    }

    public void testFindPathsWithMaximumDistance() {
        ArrayList solutions = (ArrayList) finder.findPathsWithMaximumDistance(C, C, 29);
        Iterator iter = solutions.iterator();
        System.out.println("Solutions for C, C with maximum distance < 30");
        while (iter.hasNext()) {
            Path p = (Path) iter.next();
            //assertTrue(sol.equals("C-D-C") || sol.equals("C-E-B-C"));
            System.out.println(p + " Distance : " + graph.getEdgeWeight(p));
        }
    }
    
}
